<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateQiiMemberApplyTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'qii_member_apply';

    /**
     * Run the migrations.
     * @table qii_member_apply
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->set_schema_table)) return;
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id')->comment('ID');
            $table->unsignedInteger('user_id')->default('0')->comment('会员ID');
            $table->unsignedInteger('roles_id')->default('0')->comment('申请成为的角色ID');
            $table->text('infos')->comment('申请资料');
            $table->tinyInteger('is_checked')->default('0')->comment('是否已经处理完成(0未处理, 1已通过，-1已拒绝)');
            $table->unsignedTinyInteger('is_allow')->default('0')->comment('是否允许再申请(0不允许, 1允许)');

            $table->index(["user_id", "roles_id", "is_checked"], 'user_roles');

            $table->index(["user_id", "roles_id", "is_allow"], 'is_allow');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
